/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package model.dao;

import java.util.ArrayList;
import model.entities.Tblcliente;
import org.hibernate.Session;
import org.hibernate.Transaction;

/**
 *
 * @author tey
 */
public class TblclienteDAOImplement implements TblcienteDAO{
    Transaction transaction=null;
    Session session;
    

    @Override
    public boolean agregar(Tblcliente cliente) {
        try{
            session=HibernateUtil.getSessionFactory().getCurrentSession();
            transaction=session.beginTransaction();
            session.save(cliente);
            transaction.commit();
            return true;
        }catch(Exception e){
            if(transaction !=null)
                transaction.rollback();
            return false;
        }
        
    }

    @Override
    public ArrayList<Tblcliente> listar() {
        try{
            Session session;
            Transaction transaction;
            
            session=HibernateUtil.getSessionFactory().getCurrentSession();
            transaction=session.beginTransaction();
            return (ArrayList<Tblcliente>)session.createQuery("from tblcliente").list();
            
          
                  
        
        }
        catch(Exception e){
            return null;
            
        }
    }
    
    
    
    
    
}
